
package sr.codemg.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sr.codemg.config.RedisUtil;
import sr.codemg.entity.SysParams;
import sr.codemg.service.SysParamsService;
import sr.codemg.utils.Constants;
import sr.codemg.utils.ResponseCode;
import sr.codemg.vm.Base;
import sr.codemg.vm.Tables;

import java.util.Map;
import java.util.Set;

/**
 * 参数信息
 **/
@Slf4j
@RestController
@RequestMapping("/sysparams")
public class SysParamsController {

    @Autowired
    SysParamsService sysParamsService;

    @Autowired
    private RedisUtil redisUtil;

    @GetMapping("/{id}")
    public SysParams get(@PathVariable("id") String id) {
        return sysParamsService.get(id);
    }

    @PutMapping
    public Tables list(@RequestBody Map<String, Object> params) {
        return sysParamsService.findList(params);
    }

    @PostMapping
    public Base.Response post(@RequestBody SysParams entity) {
        entity.setId(null);
        return sysParamsService.add(entity);
    }

    @PutMapping("/edit")
    public Base.Response put(@RequestBody SysParams entity) {
        return sysParamsService.update(entity);
    }

    @DeleteMapping("/{id}")
    public Base.Response delete(@PathVariable("id") String id) {
        return sysParamsService.delete(id);
    }

    @PostMapping("/refresh")
    public Base.Response refresh() {
        sysParamsService.refresh();
        return ResponseCode.getBase(Constants.SUCC);
    }

    @GetMapping("/select/{groupId}")
    public Set<SysParams> select(@PathVariable("groupId") String groupId, String in, String notIn) {
        return sysParamsService.select(groupId, in, notIn);
    }
}

